﻿using System;
using Blockey.ScreenManagers;
using BlockeyEssentials;
using BlockeyEssentials.Drawing;
using BlockeyEssentials.Input;
using BlockeyEssentials.ScreenSystem;
using BlockeyEssentials.ScreenSystem.ScreenTypes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Blockey.MenuSystemScreens
{
    public class AttemptHostScreen : Screen
    {
        public AttemptHostScreen(ScreenManager oManager, Screen oParent)
            : base(oManager)
        {
            _Parent = oParent;
            TransitionRate *= 2;

            _TextFont = new Font(All.Font_Debug);
            _TextFont.Color = Color.Black;
            _TextFont.Layer = 97;

            var oWidth = (int)(All.Resolution.Width * 0.75f);
            var oHeight = (int)(All.Resolution.Height * 0.75f);
            var oX = (All.Resolution.Width - oWidth) / 2;
            var oY = (All.Resolution.Height - oHeight) / 2;

            var oBounds = new Rectangle(oX, oY, oWidth, oHeight);
            _Sprite = new SpriteR(All.Texture_Square, oBounds);
            _Sprite.Layer = 96;
            _Sprite.Color = Color.Green;
        }

        #region Methods

        public override void Update()
        {
            if (Active)
            {
                Input();
            }
        }

        public override void Draw(SpriteBatch oSB)
        {
            _Sprite.Draw(oSB, Transition);
        }

        public override void ActionWhenFullyAdded()
        {
            var oCallback = new AsyncCallback(GoToMatch);
            Networking.StartCreateSession(oCallback);
        }

        #region Helper Methods

        private void Input()
        {
            var oInput = InputManager.Keyboard;

            //if (oInput.JustPressed(Keys.D))
            //{
            //    Cancel();
            //    return;
            //}
        }

        private void Cancel()
        {

        }

        #endregion

        #region IAsyncResult Methods

        private void GoToMatch(IAsyncResult oResult)
        {
            _DestinationManager = new GameplayManager3D(_Manager.Game);
            _Manager.RemoveAllScreens();
            Remove();
        }

        #endregion

        #endregion

        private SpriteR _Sprite;
        private Font _TextFont;
        private Screen _Parent;

    }
}
